package cn.zkcloud.util;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * 读取配置文件类
 * @Author zk
 * @Date 2017/6/18.
 * @Email zkdcloud_cn@163.com
 */
public class Proty {
    private static Logger logger = Logger.getLogger(Proty.class);

    private static String STATIC_PATHS = "staticPath";

    private static Properties properties = new Properties();

    private static List<String> staticPaths = new ArrayList<String>();

    static {
        try {
            properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("start.properties"));
        } catch (IOException e) {
            logger.error("can't read start.properties");
        }
    }

    /**
     *  init static path
     */
    static {
        String[] sps =  properties.getProperty(STATIC_PATHS).split(",");
        for(String staticPath : sps){
            staticPaths.add(staticPath.trim());
        }
    }

    /**
     *  处理静态资源内部类
     */
    public static class StaticResources{

        public static boolean isStaticPath(String path){
            for(String antPath : staticPaths){
                if(AntPathMatcher.match(antPath,path))
                    return true;
            }
            return false;
        }
    }
}
